﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using PairingMatrix.Common.Enum;

namespace PairingMatrix.View.Converter
{
    public class DateTimeToTextConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return ((DateTime)value).ToString("dd/MM/yyyy");
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string)
            {
                DateTime date;
                DateTime.TryParseExact((string)value, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
                return date;
            }
            return DateTime.MinValue;
        }
    }
}
